package com.xingkeduo.business.operation.service;

import com.xingkeduo.dao.database.DatabaseAccessObject;
import com.xingkeduo.pojo.query.DeptmentQuery;
import com.xingkeduo.pojo.table.DeptmentTable;
import com.xingkeduo.util.pojo.domain.Page;
import com.xingkeduo.util.tool.CommonUtil;
import com.xingkeduo.util.tool.IdentityUtil;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 文件概述
 *
 * @author wangxilong <wangxilong@xingkeduo.com>
 * @version id:v0.1 ${date}${time}
 * @package BeautyOS
 * @copyright Copyright (c) XKD 2019
 */
@Component
public class DeptmentService {
    private static final String NAMESPACE = DeptmentTable.class.getSimpleName();

    @Resource(name = "mysqlOperationDao")
    private DatabaseAccessObject<DeptmentTable, DeptmentQuery> dao;

    //查询一条
    public DeptmentTable selectById(long id) throws Throwable {
        DeptmentTable deptmentTable = dao.select(NAMESPACE, id);
        if (!CommonUtil.isEmpty(deptmentTable))
            return deptmentTable;
        return null;
    }

    //查询多条
    public List<DeptmentTable> selectLists(DeptmentQuery deptmentQuery) throws Throwable {
        List<DeptmentTable> deptmentTableList = dao.select(NAMESPACE, deptmentQuery);
        if (!CommonUtil.isEmpty(deptmentTableList))
            return deptmentTableList;
        return null;
    }

    //分页查询
    public Page<DeptmentTable> selectPageLists(DeptmentQuery deptmentQuery, Integer pageNo, Integer pageSize) throws Throwable {
        Page<DeptmentTable> deptmentTablePage = dao.pageSelect(NAMESPACE,deptmentQuery,pageNo,pageSize);
        return deptmentTablePage;
    }

    //插入
    public int insert(DeptmentTable deptmentTable) throws Throwable {
        deptmentTable.setCode(IdentityUtil.nextId(IdentityUtil.Worker.USER));
        return dao.insert(NAMESPACE, deptmentTable);
    }

    //更新
    public int update(DeptmentTable deptmentTable) throws Throwable {
        return dao.update(NAMESPACE, deptmentTable);
    }

    //删除
    public int delete(DeptmentTable deptmentTable) throws Throwable {
        return dao.update(NAMESPACE, deptmentTable);
    }

    //数量
    public int count(DeptmentQuery deptmentQuery) throws Throwable {
        return dao.selectCount(NAMESPACE, deptmentQuery);
    }

}
